home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000141_icon-group-sender _Tue Jun 22 12:32:44 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id MAA00996
for icon-group-addresses; Tue, 22 Jun 1999 12:32:19 -0700 (MST)
Message-Id: <199906221932.MAA00996@baskerville.CS.Arizona.EDU>
Date: Tue, 22 Jun 1999 10:22:34 -0700
From: Steve Wampler <swampler@noao.edu>
X-Accept-Language: en
To: Kostas Oikonomou <oikonomou@att.com>, icon-group@optima.CS.Arizona.EDU
Subject: Re: Assertions in Icon
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Kostas Oikonomou wrote:
>
> Hello,
>
> Does anyone have a suggestion about how to implement a procedure "assert",
> which, when called with an expression "e" as argument, implements
>
> e | stop("Assertion on line ", &line, " failed!")
>
> Here &line should be the line on which assert(e) appears.
> Thanks.
Hard!
As far as I know, there is no easy way to get the line number from
which a procedure was called (too bad, the interpreter must have this
information around or it couldn't generate the traceback messages).
Maybe someone knows of a way to get to this information (I assume it
can be an expensive solution, since the program is going to stop
immediately afterwards)?
About the best I can is to have the call pass down the current line
number, as shown in the following example:
----
procedure main()
assert{3 > 5, &line}
end
procedure assert(e)
if not @e[1] then {
stop(&errout, "Assertion failed on line ", @e[2] | "unknown")
}
end
----
Note that the call to assert is really a PDCO (Programmer Defined
Control Operation)
to delay evaluation of the expression until inside the assert procedure.
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu